﻿import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQml 2.3
import Qt.labs.platform 1.1

Window {
    id: rootWindow
    title: qsTr("ChatOnline 1.0")
    width: 380
    height: 640
    visible: true
    color: "#00000000"
    flags: Qt.Window | Qt.FramelessWindowHint

    FontLoader { id: kuaikanshijietiFont; source: "qrc:/font/kuaikanshijieti.ttf" }


    Loader{
        id: showPageLoader
        visible: true
        anchors.fill: parent
    }

    SystemTrayIcon {
        visible: true
        icon.source: "qrc:/img/chatonline.png"
        tooltip: "在线聊天"
        menu: Menu {
                 MenuItem {
                     text: qsTr("主界面")
                     onTriggered: show()
                 }
                 MenuItem {
                     text: qsTr("退出")
                     onTriggered: Qt.quit()
                 }
             }

    }


    Component.onCompleted:{
        var dbIsOk = dbManager.initDBManager()
        showPageLoader.source = "qrc:/StartShowIMGComponent.qml"

        var _ran1 = (Math.floor(Math.random()*1000)).toString()
        var _ran2 = (Math.floor(Math.random()*1000)).toString()
        var name = "用户_" + _ran1
        var number = _ran1 + _ran2
        var img = ""
        dbManager.insertUserInfo("UserInfo", name, number)
        dbManager.updateMachineInfo("UserInfo")

        var listData = dbManager.queryUserInfo("UserInfo")
        var curruntPort = listData[0].port
        var socketIsOk = socketManager.initNetwork(curruntPort)

        console.log("数据库状态：", dbIsOk)
        console.log("网络连接状态：", socketIsOk)
    }
}

